home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 June / EnigmA AMIGA RUN 19 (1997)(G.R. Edizioni)(IT)[!][issue 1997-06][EAR-CD III].iso / softwareupdate / system / atapi_pnp300 / developer_kit / showtoc.c < prev    next >
C/C++ Source or Header  |  1996-01-21  |  4KB  |  100 lines

  1. /****************************************************************************
  2. *
  3. *
  4. *   $VER: ShowTOC.c  1.0 (22 Jan 1996) by M_Campinoti CD++
  5. *
  6. *   $HISTORY:
  7. *
  8. *   22 Jan 1996 : 001.000 : First and Last release of an example that show
  9. *                           how to read and use a CDROM TableOfContents.
  10. *                           Didactical use, so CLI only      :)
  11. *
  12. ****************************************************************************/
  13.  
  14. #include <proto/exec.h>
  15. #include <exec/devices.h>
  16. #include <exec/io.h>
  17. #include <stdio.h>
  18.  
  19. #include "atapi_cd.h"
  20.  
  21.  
  22. main (UBYTE argc,UBYTE **argv)
  23. {
  24.     struct IOStdReq      *ioreq = NULL ;
  25.     struct MsgPort       *reply = NULL ;
  26.     
  27.     union CDTOC          tocarray[100];  /* Max 99 tracks + summary */
  28.     
  29.     UBYTE                firsttrack;
  30.     UBYTE                lasttrack;
  31.     ULONG                totalsectors;
  32.     UBYTE                entries;
  33.  
  34.     if (argc==0) return;   /* it came from workbench ..... */
  35.  
  36.     if( reply = CreateMsgPort() )
  37.     {
  38.       if( ioreq = (struct IOStdReq *)
  39.              CreateIORequest(reply ,sizeof(struct  IOStdReq)) )
  40.       {
  41.         if(!OpenDevice("cd.device",0,(struct IORequest*)ioreq,NULL) )
  42.         {
  43.           ioreq->io_Command = CD_TOCLSN;        /* Retrieve TOC information */
  44.           ioreq->io_Offset  = 0;                /* Start with summary info  */
  45.           ioreq->io_Length  = 100;              /* Max 99 tracks + summary  */
  46.           ioreq->io_Data    = (APTR)tocarray;   /* Here's where we want it  */
  47.  
  48.           DoIO((struct IORequest*)ioreq);
  49.           
  50.           if (!ioreq->io_Error)                   /* Command succeeded        */
  51.           {
  52.             
  53.             /* Now we read the TOC Summary of our CD ...    */
  54.             
  55.             firsttrack   = tocarray[0].Summary.FirstTrack;
  56.             lasttrack    = tocarray[0].Summary.LastTrack;
  57.             totalsectors = tocarray[0].Summary.LeadOut.LSN - tocarray[1].Entry.Position.LSN;
  58.           
  59.             /* ... and here we printout the results !          */
  60.             
  61.             printf("------------------------------------------\n");
  62.             printf("| ShowTOC ©1995-1996 by M.Campinoti CD++ |\n");
  63.             printf("------------------------------------------\n");
  64.             printf("    First Track : %d\n",firsttrack);
  65.             printf("    Last  Track : %d\n",lasttrack);
  66.             printf("    Total Tracks: %d\n",(lasttrack-firsttrack)+1);
  67.             printf("------------------------------------------\n");
  68.             printf("    Total Sectors: %d\n",totalsectors);
  69.             printf("------------------------------------------\n\n");
  70.             
  71.             printf("---Track Number------Position (LSN Format)--\n");
  72.             for(entries=1;entries<=lasttrack;entries++)
  73.             {
  74.                 if(entries<10)
  75.                     printf("    %d                  %d \n",
  76.                             tocarray[entries].Entry.Track,
  77.                             tocarray[entries].Entry.Position);
  78.                 else
  79.                     printf("    %d                 %d \n",
  80.                             tocarray[entries].Entry.Track,
  81.                             tocarray[entries].Entry.Position);
  82.  
  83.             }
  84.             printf("------------------------------------------\n\n");
  85.           
  86.           }
  87.           else printf("I/O error !\n");      /* analyze ioreq->io_Error to know what kind ... */
  88.                                              /* ... see atapi_cd.h for #defines of it !       */
  89.           
  90.           CloseDevice((struct IORequest *)ioreq) ;
  91.         }
  92.         
  93.         DeleteIORequest(ioreq) ;
  94.       }
  95.  
  96.       DeleteMsgPort(reply);
  97.     }
  98. }
  99.  
  100.